﻿using Abp.Application.Services;
using NetCore.Entities;
using NetCore.Services;
using System;
using System.Reflection;

namespace NetCore.Factory
{
    /// <summary>
    /// 泛型简单工厂:通过配置文件+反射创建实例
    /// 去掉泛型 CreateInstance也可以返回一个object对象
    /// </summary>
    public class ModelFactory<TEntity> where TEntity : BaseEntity
    {
        private static readonly Type DllType = null;

        static ModelFactory()
        {
            Assembly assembly = Assembly.Load(ServiceConsts.DllName);//StaticConstant
            DllType = assembly.GetType(ServiceConsts.TypeName);
        }

        public static IApplicationService CreateInstance()
        {
            return (IApplicationService)Activator.CreateInstance(DllType);
        }

    }
}
